<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    //1.实例化 xhr 对象
    var xhr = new XMLHttpRequest();
    //2.调用 open()方法
    xhr.open('get','/api/getStr');
    //3.调用 send()方法发送Ajax请求
    xhr.send();
    //4.使用onload事件来接收后端返回的数据
    xhr.onload = function(){
        alert(xhr.responseText);
    };
  </script>
</body>
</html>